<?php
	include("../../includes/ez_sql_core.php");
	include("../../includes/ez_sql_mysql.php");

	if(isset($_POST["nick"]))
	{
		$nick = $_POST["nick"];

		$db = new ezSQL_mysql("root","","biblioteca","localhost");

		$usuario = $db->get_row("SELECT *
		 						FROM usuarios
		 						WHERE nick='" . $nick . "'", ARRAY_A);


		if($db->num_rows != 0)
		{

			$db->get_results("SELECT *
	  					  FROM usuarios AS u, administradores AS a
	  					  WHERE u.codigo = a.codigo AND u.nick='" . $nick . "'");

			if($db->num_rows != 0)
			{
				$usuario["rol"] = "administrador";
			}

			$db->get_results("SELECT *
		  					  FROM usuarios AS u, moderadores AS m
		  					  WHERE u.codigo = m.codigo AND u.nick='" . $nick . "'");

			if($db->num_rows != 0)
			{
				$usuario["rol"] = "moderador";
			}

			$db->get_results("SELECT b.tipo AS 'tipoBaneo', b.razon AS 'razonBaneo', b.duracion AS 'fechaBaneo'
		  					  FROM usuarios AS u, baneados AS b
		  					  WHERE u.codigo = b.usuario AND u.nick='" . $nick . "'");

			if($db->num_rows != 0)
			{
				$usuario["rol"] = "baneado";
				$datosBaneo = $db->get_row();
				$usuario["tipoBaneo"] = $datosBaneo->tipoBaneo;
				$usuario["razonBaneo"] = $datosBaneo->razonBaneo;
				$usuario["fechaBaneo"] = $datosBaneo->fechaBaneo;
			}

			if(!isset($usuario["rol"]))
			{
				$usuario["rol"] = "usuario";
			}
		}

		echo json_encode($usuario);
	}
?>